import 'package:flutter/material.dart';
import 'package:lazy_food/favorite/all/all_page.dart';
import 'package:lazy_food/favorite/fold/fold_page.dart';
import 'package:lazy_food/favorite/history/history_page.dart';

class FavoritePage extends StatefulWidget {
  @override
  State<FavoritePage> createState() => _FavoritePageState();
}

class _FavoritePageState extends State<FavoritePage>
    with AutomaticKeepAliveClientMixin, SingleTickerProviderStateMixin {
  List _tabs = ['全部收藏', '收藏夹', '最近观看'];
  List<Widget> _tabviews = [
    AllPage(),
    FoldPage(),
    HistoryPage(),
  ];
  late TabController _tabController;

  @override
  // TODO: implement wantKeepAlive
  bool get wantKeepAlive => true;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _tabController = TabController(length: _tabs.length, vsync: this);
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Scaffold(
      appBar: AppBar(
        title: Row(
          children: [
            Expanded(
              child: GestureDetector(
                child: Container(
                  height: 40,
                  padding: EdgeInsets.only(left: 20),
                  alignment: Alignment.centerLeft,
                  child: Row(
                    children: [
                      Icon(
                        Icons.search,
                        color: Colors.white,
                        size: 20,
                      ),
                      SizedBox(
                        width: 5,
                      ),
                      Text(
                        '搜索收藏',
                        style: TextStyle(color: Colors.white, fontSize: 14),
                      ),
                    ],
                  ),
                  decoration: BoxDecoration(
                    color: Colors.white30,
                    borderRadius: BorderRadius.circular(20),
                  ),
                ),
                onTap: () {
                  print('点击搜索');
                },
              ),
            ),
            IconButton(
              onPressed: () {
                print('点击编辑');
              },
              icon: Icon(
                Icons.edit,
                color: Colors.white,
                size: 30,
              ),
            )
          ],
        ),
        shadowColor: null,
        backgroundColor: Colors.black,
        bottom: PreferredSize(
          child: Align(
            alignment: Alignment.centerLeft,
            child: TabBar(
              tabs: _tabs.map((e) => Text(e)).toList(),
              controller: _tabController,
              isScrollable: true,
              padding: EdgeInsets.only(left: 10, right: 10, top: 0, bottom: 0),
              unselectedLabelColor: Colors.white54,
              labelColor: Colors.black,
              labelStyle: TextStyle(fontSize: 16),
              indicatorPadding: EdgeInsets.fromLTRB(0, -5, 0, -5),
              indicator: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(16)),
              ),
            ),
          ),
          preferredSize: Size.fromHeight(40),
        ),
      ),
      body: TabBarView(
        children: _tabviews,
        controller: _tabController,
      ),
      backgroundColor: Colors.black,
    );
  }
}
